use dss_lms;
drop trigger if exists Update_Balance ; 
DELIMITER $$
CREATE TRIGGER Update_Balance 
BEFORE UPDATE ON account 
FOR EACH ROW
BEGIN
    IF NEW.TransactionType = 'Credit' THEN 
        UPDATE location SET TotalBalance =TotalBalance + NEW.Amount WHERE LocationID=NEW.LocationID;
    ELSEIF NEW.TransactionType = 'Debit' THEN 
        UPDATE location SET TotalBalance=TotalBalance - NEW.Amount WHERE LocationID=NEW.LocationID;
    END IF;
END$$
DELIMITER ;